﻿-- ================================================
-- Remarks: 
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Ivy_Society_Insert]') AND type in (N'P', N'PC'))
DROP PROCEDURE [Ivy_Society_Insert]
GO



CREATE PROCEDURE [Ivy_Society_Insert] 
-- =============================================
-- Author:		<Sagar sk>
-- Create date: <01/08/2014>
-- Description:	<Ivy_User_Insert>
-- =============================================

-- Add the parameters for the stored procedure here
	(
				@SocietyCode varchar(100),
				@SocietyName varchar(150),
				@SocietyAddressLine1 varchar(300),
				@SocietyAddressLine2 varchar(300),
				@SocietyAddressCity varchar(200),
				@SocietyAddressState varchar(200),
				@SocietyAddressCountry varchar(200),
				@SocietyAddressZip varchar(200),
				
				
				@Sys_CreatedByID varchar(50)= NULL,
				@Sys_ModifiedByID varchar(50) = NULL,
				@Sys_DeleteType int = 0,
				@Sys_OrganizationID int = NULL,
				@Sys_InitialPrimaryKeys varchar(max)= NULL,
				@Sys_WorkstationName varchar(50)= NULL,
				
				@Sys_DateOfCreation datetime OUTPUT,
				@SocietyKey int OUTPUT
	)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT OFF;

	IF @Sys_WorkstationName = 'Default'	
	BEGIN
		SET @Sys_WorkstationName = (SELECT @@SERVERNAME);
	END
	DECLARE @CurrentDataTime datetime;
	SET @CurrentDataTime = GETDATE();
	
    INSERT INTO [Society]
           (	
				[SocietyCode],
				[SocietyName],
				[SocietyAddressLine1],
				[SocietyAddressLine2],
				[SocietyAddressCity],
				[SocietyAddressState],
				[SocietyAddressCountry],
				[SocietyAddressZip],
				[Sys_DateOfCreation],
				[Sys_DateOfModification],
				[Sys_CreatedByID],
				[Sys_ModifiedByID],
				[Sys_DeleteType],
				[Sys_IsDeleted],
				[Sys_OrganizationID],
				[Sys_InitialPrimaryKeys],
				[Sys_WorkstationName]
			)
     VALUES
           (
				@SocietyCode,
				@SocietyName,
				@SocietyAddressLine1,
				@SocietyAddressLine2,
				@SocietyAddressCity,
				@SocietyAddressState,
				@SocietyAddressCountry,
				@SocietyAddressZip,
				@CurrentDataTime,
				@CurrentDataTime,
				@Sys_CreatedByID,
				@Sys_CreatedByID,
				@Sys_DeleteType,
				0,
				@Sys_OrganizationID,
				@Sys_InitialPrimaryKeys,
				@Sys_WorkstationName
			);
	SET @SocietyKey = SCOPE_IDENTITY();
	SET @Sys_DateOfCreation = @CurrentDataTime;
	EXEC Ivy_Sys_OrganizationMaster_Insert @SocietyKey,@SocietyName,'Housing Society Association','www.mysociety.com',@Sys_CreatedByID,0,-1,NULL, @Sys_WorkstationName;
END


GO


